﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Xml.Serialization;
using System.ComponentModel;

namespace BDSim
{
    #region 地面位置信息结构体

    /// <summary>
    /// 卫星轨道位置速度结构体
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct NodePosVel
    {
        /// <summary>
        /// 轨道历元
        /// </summary>
        public UTCTime epoch;
        [XmlAttribute]
        public double x;
        [XmlAttribute]
        public double y;
        [XmlAttribute]
        public double z;
        [XmlAttribute]
        public double vx;
        [XmlAttribute]
        public double vy;
        [XmlAttribute]
        public double vz;
        [XmlIgnore]
        public double X { get { return x; } set { x = value; } }
        [XmlIgnore]
        public double Y { get { return y; } set { y = value; } }
        [XmlIgnore]
        public double Z { get { return z; } set { z = value; } }
        [XmlIgnore]
        public double VX { get { return vx; } set { vx = value; } }
        [XmlIgnore]
        public double VY { get { return vy; } set { vy = value; } }
        [XmlIgnore]
        public double VZ { get { return vz; } set { vz = value; } }
        [XmlIgnore]
        public UTCTime Epoch { get { return epoch; } set { epoch = value; } }

        public NodePosVel(UTCTime e, double Px, double Py, double Pz, double Vx, double Vy, double Vz)
        {
            epoch = e;
            x = Px;
            y = Py;
            z = Pz;
            vx = Vx;
            vy = Vy;
            vz = Vz;
        }

        public NodePosVel(UTCTime e)
        {
            epoch = e;
            x = y = z = vx = vy = vz = 0;
        }

        public NodePosVel(double Px, double Py, double Pz, double Vx, double Vy, double Vz)
        {
            epoch = new UTCTime();
            x = Px;
            y = Py;
            z = Pz;
            vx = Vx;
            vy = Vy;
            vz = Vz;
        }

        /// <summary>
        /// 把结构体转为类
        /// </summary>
        /// <returns></returns>
        public NodePosVelClass ConvertToClass()
        {
            NodePosVelClass PosVel = new NodePosVelClass();
            PosVel.Epoch = Epoch.ToUTCTimeClass();
            PosVel.X = x;
            PosVel.Y = y;
            PosVel.Z = z;
            PosVel.VX = vx;
            PosVel.VY = vy;
            PosVel.VZ = vz;
            return PosVel;
        }
    };

    //该结构体用NodePosVel代替
    /// <summary>
    /// 表示一个直角坐标系的点，三维
    /// </summary>
    //public struct PosXYZ
    //{
    //    public double X;
    //    public double Y;
    //    public double Z;
    //}

    /// <summary>
    /// 直角坐标系表示的地固坐标系，用于定义界面属性参数
    /// </summary>
    [TypeConverter(typeof(ExpandableObjectConverter))]
    public class PosXYZClass
    {
        private double x = -2148744.3968999996;

        [XmlAttribute, DescriptionAttribute("X方向位置（偏移），单位(米)")]
        public double X
        {
            get { return x; }
            set { x = value; }
        }
        private double y = 4426641.2099;

        [XmlAttribute, DescriptionAttribute("Y方向位置（偏移），单位(米)")]
        public double Y
        {
            get { return y; }
            set { y = value; }
        }
        private double z = 4044655.8564000013;

        [XmlAttribute, DescriptionAttribute("Z方向位置（偏移），单位(米)")]
        public double Z
        {
            get { return z; }
            set { z = value; }
        }

        public override string ToString()
        {
            return string.Empty;
        }
    }


    //该结构体用BLH_PosVel代替
    /// <summary>
    /// 表示一个大地坐标系的点，三维
    /// </summary>
    //public struct PosBLH
    //{
    //    public double B;    //纬度
    //    public double L;    //经度
    //    public double H;    //高度
    //    public PosBLH(double B, double L, double H)
    //    {
    //        this.B = B;
    //        this.L = L;
    //        this.H = H;
    //    }
    //}

    /// <summary>
    /// 大地坐标系表示的地固坐标系，用于定义界面属性参数
    /// </summary>
    [TypeConverter(typeof(ExpandableObjectConverter))]
    public class PosBLHClass
    {
        private double b = 39.60860038735;

        [XmlAttribute, DescriptionAttribute("初始纬度，单位(度)，范围：-90~+90"),PropertyOrder(1)]
        public double B
        {
            get { return b; }
            set { b = value; }
        }
        private double l = 115.8924888757755;

        [XmlAttribute, DescriptionAttribute("初始经度，单位(度)，范围：-180~+180"), PropertyOrder(2)]
        public double L
        {
            get { return l; }
            set { l = value; }
        }
        private double h=87.471737776882946;

         [XmlAttribute, DescriptionAttribute("初始高程，单位(米)"), PropertyOrder(3)]
        public double H
        {
            get { return h; }
            set { h = value; }
        }

         public override string ToString()
         {
             return B.ToString() + ", " + L.ToString() + ", " + H.ToString();
         }

         public BLH_PosVel ToPosVelStruct()
         {
             BLH_PosVel pos = new BLH_PosVel();
             pos.B = B;
             pos.L = L;
             pos.H = H;
             return pos;
         }
    }

    /// <summary>
    /// 三维位置速度(经纬高)
    /// </summary>
    public struct BLH_PosVel
    {
        public UTCTime epoch; //轨道历元 
        [XmlAttribute]
        public double B;    //纬度
        [XmlAttribute]
        public double L;    //经度
        [XmlAttribute]
        public double H;    //高度
        [XmlAttribute]
        public double v_B;
        [XmlAttribute]
        public double v_L;
        [XmlAttribute]
        public double v_H;

        /// <summary>
        /// 默认值 
        /// </summary>
        //public static BLH_PosVel Default()
        //{
        //    get
        //    {
        //        UTCTime time=new UTCTime();
        //        return new BLH_PosVel(time,0,0,0,0,0,0);
        //    }

        //}
        //public BLH_PosVel(UTCTime e, double b, double l, double h, double vH, double vL, double vB)
        //{
        //    epoch = e;
        //    B = b;
        //    H = h;
        //    L = l;
        //    v_B = vB;
        //    v_H = vH;
        //    v_L = vL;
        //}

    }

    //RTN位置 速度
    public struct RTN_PosVel 
    {
        [XmlAttribute]
        public double R;
        [XmlAttribute]
        public double T;
        [XmlAttribute]
        public double N;
        [XmlAttribute]
        public double vR;
        [XmlAttribute]
        public double vT;
        [XmlAttribute]
        public double vN;
        public UTCTime epoch;
        public RTN_PosVel(UTCTime e, double r, double t, double n, double vr, double vt, double vn)
        {
            epoch = e;
            R = r;
            T = t;
            N = n;
            vR = vr;
            vT = vt;
            vN = vn;
        }

        //public RTN_PosVel()
        //{
        //    epoch = new UTCTime();
        //    R = 0;
        //    T = 0;
        //    N = 0;
        //    vR = 0;
        //    vT = 0;
        //    vN = 0;
        //}
    }

    //东北天   新增（2015.10.29）
    public struct ENU_PosVel
    {
        public UTCTime epoch; //轨道历元

        [XmlAttribute]
        public double E;
        [XmlAttribute]
        public double N;
        [XmlAttribute]
        public double U;
        [XmlAttribute]
        public double v_E;
        [XmlAttribute]
        public double v_N;
        [XmlAttribute]
        public double v_U;

        //public ENU_PosVel()
        //{
        //    epoch = new UTCTime();
        //    E = N = U = v_E = v_N = v_U = 0;
        //}
        public ENU_PosVel(UTCTime time, double e, double n, double u, double ve, double vn, double vu)
        {
            epoch = time;
            E = e;
            N = n;
            U = u;
            v_E = ve;
            v_N = vn;
            v_U = vu;
        }

    }

    /// <summary>
    /// 直角坐标系表示的地固坐标系，用于定义界面属性参数
    /// </summary>
    [TypeConverter(typeof(ExpandableObjectConverter))]
    public class PosENUClass
    {
        private double e = 0.0007;

        [XmlAttribute, DescriptionAttribute("E方向位置（偏移），单位(米)")]
        public double E
        {
            get { return e; }
            set { e = value; }
        }
        private double n = -0.0005;

        [XmlAttribute, DescriptionAttribute("N方向位置（偏移），单位(米)")]
        public double N
        {
            get { return n; }
            set { n = value; }
        }
        private double u = 0.0908;

        [XmlAttribute, DescriptionAttribute("U方向位置（偏移），单位(米)")]
        public double U
        {
            get { return u; }
            set { u = value; }
        }

        public override string ToString()
        {
            return string.Empty;
        }
    }

    /// <summary>
    /// 球坐标
    /// </summary>
    public struct Sphere_PosVel
    {
        [XmlAttribute]
        public double alpha;
        [XmlAttribute]
        public double delta;
        [XmlAttribute]
        public double d;
        [XmlAttribute]
        public double Valpha;
        [XmlAttribute]
        public double Vdelta;
        [XmlAttribute]
        public double Vd;
	    public UTCTime epoch;

        //Sphere_PosVel()
        //{
        //  alpha=0.0;
        //  delta=0.0;
        //  d=0.0;
        //  Valpha=0.0;
        //  Vdelta=0.0;
        //  Vd=0.0;
        //    epoch=new UTCTime();
        //}

	    Sphere_PosVel(UTCTime e, double In_alpha,double In_delta,double In_d,double In_Valpha,double In_Vdelta,double In_Vd)
	    {
            epoch=e;
		    alpha=In_alpha;
		    delta=In_delta;
		    d=In_d;
		    Valpha=In_Valpha;
	        Vdelta=In_Vdelta;
	        Vd=In_Vd;

	    }
    };

    //坐标转换的7参数
    public struct CoordConvertPara
    {
        /// <summary>
        /// 旋转参数
        /// </summary>
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
        public double[] roatepara;
        /// <summary>
        /// 偏移参数
        /// </summary>
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
        public double[] offset;
        /// <summary>
        /// 比例因子
        /// </summary>
        public double m;
        //public CoordConvertPara()
        //{
        //    m = 0.0;
        //    offset = new double[3];
        //    roatepara = new double[3];
        //    for (int i = 0; i < 3; i++)
        //    {
        //        offset[i] = 0.0;
        //        roatepara[i] = 0.0;
        //    }
        //}

        CoordConvertPara(double[] roatepara1, double[] offset1, double m1)
        {
            m = m1;
            offset = new double[3];
            roatepara = new double[3];
            for (int i = 0; i < 3; i++)
            {
                offset[i] = offset1[i];
                roatepara[i] = roatepara1[i];
            }

        }

        CoordConvertPara(double r1, double r2, double r3, double o1, double o2, double o3, double m1)
        {
            offset = new double[3];
            roatepara = new double[3];

            roatepara[0] = r1;
            roatepara[1] = r2;
            roatepara[2] = r3;
            offset[0] = o1;
            offset[1] = o2;
            offset[2] = o3;
            m = m1;
        }

    }

    /// <summary>
    /// 坐标系统类型
    /// </summary>
    public enum ECoordinateType
    { 
        ECF,
        ECI
    }

    /// <summary>
    /// 用户的坐标类型
    /// </summary>
    public enum ECoordinateType_ECF
    {
        /// <summary>
        /// WGS84直角坐标系
        /// </summary>
        WGS84_XYZ,
        /// <summary>
        /// WGS84大地坐标系
        /// </summary>
        WGS84_BLH,
        /// <summary>
        /// CGCS2000直角坐标系
        /// </summary>
        CGCS2000_XYZ,
        /// <summary>
        /// CGCS2000大地坐标系
        /// </summary>
        CGCS2000_BLH,
    }

    /// <summary>
    /// 4种系统地固系
    /// </summary>
    public enum ECFtype
    {
        /// <summary>
        /// GPS系统
        /// </summary>
        type_WGS,
        /// <summary>
        /// GALILEO系统
        /// </summary>
        type_pz90,
        /// <summary>
        /// BD系统
        /// </summary>
        type_CGCS2000,
        /// <summary>
        /// GLONASS系统
        /// </summary>
        type_GTRF
    }

    /// <summary>
    /// 地面站位置信息（坐标类型、表现形式、三维坐标值） (Add by lhz)
    /// </summary>
    public struct StationPostion
    {
        public ECoordinateType_ECF Type;
        public NodePosVel Pos_XYZ;
        public BLH_PosVel Pos_BLH; 
    }

    #endregion

}
